# coding: utf-8
# @Author: 莫小鱼
from time import sleep

from selenium.webdriver.common.by import By
from AutoWebTest.utils.basepage import BasePage


class LoginPage(BasePage):

    # URL
    url = "https://study.seewoedu.cn/"

    # 用户名
    user_name = (By.XPATH, '//*[@id="username"]')
    # 密码
    pass_word = (By.XPATH, '//*[@id="password"]')
    # 勾选服务协议
    input_text = (By.XPATH, '//*[contains(text(),"我同意")]')
    # 勾选30天记录
    input_jilu = (By.XPATH, '//input[@id="remenber-me-checkbox"]')
    # 登录按钮
    login_btn = (By.CSS_SELECTOR, '#login-btn')
    # 希沃账号登陆
    xiwo_login = (By.CSS_SELECTOR,'#scanLoginTab')
    # 首页_登录
    home_login_ele = (By.XPATH, "/html/body/div/div/header/div/div[2]/div[3]/div/span[1]")

    # 断言结果
    assert_result = (By.XPATH, "//*[@id='login-err-text']")

    # 断言元素
    assert_element = (By.XPATH,"//*[@id='login-err-text']")

    # 断言文本信息
    expect_text = "账号不存在或密码错误"

    def login(self,username,password):
        # 进入首页
        self.open_url(self.url)
        sleep(5)
        # 点击首页_登录
        self.click(self.home_login_ele)
        sleep(1)
        # 点击 希沃账号登陆
        self.click(self.xiwo_login)
        sleep(1)
        # 输入 username
        self.send_keys(self.user_name,username)
        sleep(1)
        # 输入 密码
        self.send_keys(self.pass_word,password)
        sleep(1)
        # 点击 服务协议
        self.click(self.input_text)
        sleep(1)
        # 点击 保持记录
        self.click(self.input_jilu)
        sleep(1)
        # 点击 登录 按钮
        self.click(self.login_btn)
        sleep(1)



